/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import BUSObject.Product;
import DAL.DABasic;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.rowset.CachedRowSet;

/**
 *
 * @author HOANG ANH
 */
public class BUSProduct {

    private DABasic _daBasic;

    public BUSProduct() {
        _daBasic = new DABasic();
    }
    
    public ArrayList<Product> getProductList(){
        try {
            PreparedStatement preStm = _daBasic.PreparedStatement("SELECT * FROM Product");
            ArrayList<Product> productList = new ArrayList<Product>();
            CachedRowSet crd = _daBasic.ExecuteResult(preStm);
            while (crd.next()) {                
                Product p = new Product(crd.getInt(1), crd.getString(2), crd.getFloat(3));
                productList.add(p);
            }
            return productList;
        } catch (SQLException ex) {
            Logger.getLogger(BUSProduct.class.getName()).log(Level.SEVERE, null, ex);
            return new ArrayList<Product>();
        }
    }
    
    
}
